import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const busListStore = defineStore(
  'bus',
  () => {
    // 会员信息
    const busList = ref<any>()

    // 保存会员信息，登录时使用
    const setBus = (val: any) => {
      busList.value = val
    }

    // 清理会员信息，退出时使用
    const clearBus = () => {
      busList.value = undefined
    }

    // 记得 return
    return {
      busList,
      setBus,
      clearBus,
    }
  },
  // TODO: 持久化
  {
    persist: {
      // 调整为兼容多端的API
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
    },
  },
)
